<template>
  <div>
    <el-row>
      <el-col :span="24">
        <el-table :data="tableData" v-loading="tableConfig.load" :style="tableConfig.style" :max-height="tableConfig.maxHeight" :border=tableConfig.border :size="tableConfig.size" @selection-change="handleSelectionChange">
          <el-table-column v-if="tableConfig.selection === true" type="selection" width="55"> </el-table-column>
            <template v-for="(item, index) of tableConfig.config">
              <el-table-column v-if="item.id === 'radio'" :key="'radio'+index" :width="item.width">
                <template slot-scope="scope">
                  <el-radio v-model="radio" :label="scope.row.id">&nbsp;</el-radio>
                </template>
              </el-table-column>
              <el-table-column v-else-if="item.id === 'operation'" :key="index" :prop="item.id" :label="item.name" :align="tableConfig.align?tableConfig.align:'center'" :width="item.width">
                <template slot-scope="scope"> <el-button v-for="n in item.list" :key="n.id" @click="examine(scope.row, n.id, scope.$index)" type="text" size="small" :class="n.className">{{n.name}}</el-button> </template>
              </el-table-column>
              <el-table-column v-else :label="item.name" :key="index" :prop="item.id" :align="tableConfig.align?tableConfig.align:'center'" :width="item.width" :type="item.type"></el-table-column>
            </template>
        </el-table>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data () {
    return {
      radio: null
    }
  },
  name: 'tableList',
  props: ['tableConfig', 'tableData'],
  methods: {
    examine (rows, id, index) {
      this.$emit('operation', {id: id, rows: rows, index: index})
    },
    handleSelectionChange (val) {
      this.$emit('handleSelectionChange', {val: val})
    }
  },
  watch: {
    'radio': function (newVal) {
      this.tableData.forEach(item => {
        if (newVal === item.id) {
          this.$emit('noRadio', {val: item})
        }
      })
    }
  }
}
</script>
